import { hasToken } from '@/utils/storage'
import React from 'react'
import { Route, Redirect } from 'react-router-dom'
// 我们需要解构所有的属性，除了component属性
export default function PrivateRoute(porps) {
   const Component = porps.component
  return (
    <Route
      // path = {porps.path} 子组件内部没有 porps参数
      {...porps} 
      render={() => {
        if (hasToken()) {
          return <Component></Component>
        } else {
          return <Redirect to={{pathname:"/login",state:porps.location.pathname}}></Redirect>
        }
      }}
    ></Route>
  )
}